package pl.enigmatic.parser.markup;

import pl.enigmatic.util.Strings;


public abstract class BasicMarkupExtension implements MarkupExtension {

	public static boolean isMarkup(final String string) {
		return string != null && string.startsWith(OPENING) && string.endsWith(CLOSING);
	}

	public static String getContent(final String string) {
		return Strings.trimAllWhitespaces(string.substring(OPENING.length(), string.length() - CLOSING.length()));
	}

	public static String getName(final String string) {
		return getContent(string).split(SPACE)[0].trim();
	}

	public static String getProperties(final String string) {
		final String content = getContent(string);
		final int space = content.indexOf(SPACE);
		if (space >= 0) {
			return content.substring(space).trim();
		} else {
			return "";
		}
	}

	private final String name;

	protected BasicMarkupExtension(final String name) {
		this.name = name;
	}

	@Override
	public boolean canHandle(final Object target, final MarkupProperties props) {
		return true;
	}

	@Override
	public final String getName() {
		return name;
	}

}
